/*
 * Pratama Nur Wijaya (c) 2013 
 * 
 * Project       : Sound Of Indonesia
 * Filename      : Scene_Credit.java
 * Creation Date : Apr 23, 2013 time : 10:22:25 AM
 *
 */

package id.pratama.soundofindonesia.scene;

import id.pratama.soundofindonesia.IManageableScene;
import id.pratama.soundofindonesia.Utils;
import id.pratama.soundofindonesia.config.IApps_Data;
import id.pratama.soundofindonesia.config.IApps_Define;
import id.pratama.soundofindonesia.data.IGraphic_Data;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import android.graphics.Color;
import android.graphics.Typeface;

public class Scene_Credit extends Scene implements IManageableScene, IApps_Data, IApps_Define, IGraphic_Data
{
	private BaseGameActivity	activity;

	private BitmapTextureAtlas	texMenuBg;
	private ITextureRegion		regMenuBg;
	private Sprite				sprMenuBg;

	private Font				fontTitle;
	private Font				fontContent;
	private Font				fontContentPeople;
	private Text				textTitle;
	private Text				textSOI;
	private Text				textPratama;
	private Text				textSpecialThanks;
	private Text				textAmikomGamedev;
	private Text				textIrfan;
	private Text				textAmikom;
	private Text				textTahun;

	public Scene_Credit(BaseGameActivity activity)
	{
		this.activity = activity;
		loadResources();
		applyResources();
		registerUpdateHandler();
	}

	@Override
	public void loadResources()
	{
		if (texMenuBg == null)
			texMenuBg = new BitmapTextureAtlas(activity.getTextureManager(), MENU_UTAMA_BG_TEX_WIDTH,
					MENU_UTAMA_BG_TEX_HEIGHT, Utils.getTextureOptions());
		regMenuBg = BitmapTextureAtlasTextureRegionFactory.createFromAsset(texMenuBg, activity, MENU_UTAMA_BG, 0, 0);

		fontTitle = FontFactory.create(activity.getFontManager(), activity.getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Utils.getRatio(50), Color.WHITE);
		fontContent = FontFactory.create(activity.getFontManager(), activity.getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), Utils.getRatio(40), Color.WHITE);
		fontContentPeople = FontFactory.create(activity.getFontManager(), activity.getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Utils.getRatio(25), Color.WHITE);

		fontTitle.load();
		fontContent.load();
		fontContentPeople.load();
		texMenuBg.load();
	}

	@Override
	public void applyResources()
	{
		if (sprMenuBg == null)
			sprMenuBg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, regMenuBg, activity.getVertexBufferObjectManager());

		if (textTitle == null)
			textTitle = new Text(0, 0, fontTitle, "Credit", activity.getVertexBufferObjectManager());
		textTitle.setPosition(RES_WIDTH / 2 - textTitle.getWidth() / 2, Utils.getRatio(10));

		if (textSOI == null)
			textSOI = new Text(0, 0, fontContent, "Sound of Indonesia", activity.getVertexBufferObjectManager());
		textSOI.setPosition(RES_WIDTH / 2 - textSOI.getWidth() / 2,
				textTitle.getY() + textTitle.getHeight() + Utils.getRatio(10));

		if (textPratama == null)
			textPratama = new Text(0, 0, fontContentPeople, "Pratama Nur Wijaya",
					activity.getVertexBufferObjectManager());
		textPratama.setPosition(RES_WIDTH / 2 - textPratama.getWidth() / 2,
				textSOI.getY() + textSOI.getHeight()
						+ Utils.getRatio(10));

		if (textSpecialThanks == null)
			textSpecialThanks = new Text(0, 0, fontContent, "Special Thanks", activity.getVertexBufferObjectManager());
		textSpecialThanks.setPosition(RES_WIDTH / 2 -
				textSpecialThanks.getWidth() / 2,
				textPratama.getY() + textPratama.getHeight()
						+ Utils.getRatio(30));

		if (textIrfan == null)
			textIrfan = new Text(0, 0, fontContentPeople, "Irvan D. Efendi (Audio Engineer)",
					activity.getVertexBufferObjectManager());
		textIrfan.setPosition(RES_WIDTH / 2 - textIrfan.getWidth() / 2,
				textSpecialThanks.getY() + textSpecialThanks.getHeight()
						+ Utils.getRatio(10));

		if (textAmikomGamedev == null)
			textAmikomGamedev = new Text(0, 0, fontContentPeople, "AMIKOMGAMEDEV",
					activity.getVertexBufferObjectManager());
		textAmikomGamedev.setPosition(RES_WIDTH / 2 - textAmikomGamedev.getWidth() / 2,
				textIrfan.getY() + textIrfan.getHeight()
						+ Utils.getRatio(10));

		if (textAmikom == null)
			textAmikom = new Text(0, 0, fontContentPeople, "STMIK Amikom Yogyakarta",
					activity.getVertexBufferObjectManager());
		textAmikom.setPosition(RES_WIDTH / 2 - textAmikom.getWidth() / 2,
				textAmikomGamedev.getY() + textAmikomGamedev.getHeight()
						+ Utils.getRatio(40));
		if (textTahun == null)
			textTahun = new Text(0, 0, fontContentPeople, "2013",
					activity.getVertexBufferObjectManager());
		textTahun.setPosition(RES_WIDTH / 2 - textTahun.getWidth() / 2,
				textAmikom.getY() + textAmikom.getHeight()
						+ Utils.getRatio(10));

		attachChild(sprMenuBg);
		sprMenuBg.attachChild(textTitle);
		sprMenuBg.attachChild(textSOI);
		sprMenuBg.attachChild(textPratama);
		sprMenuBg.attachChild(textSpecialThanks);
		sprMenuBg.attachChild(textIrfan);
		sprMenuBg.attachChild(textAmikomGamedev);
		sprMenuBg.attachChild(textAmikom);
		sprMenuBg.attachChild(textTahun);
	}

	@Override
	public void registerUpdateHandler()
	{
	}

	@Override
	public void unloadResources()
	{
	}

}
